package com.example.sbbsec;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;

/**
 * Created by shuqin on 17/12/5.
 */
public class FiboCollector<T,A,R> implements Collector<T, List<A>, List<R>> {

  public Supplier<List<A>> supplier() {
    return () -> {
      List<A> result = new ArrayList<>();
      return result;
    };
  }

  @Override
  public BiConsumer<List<A>, T> accumulator() {
    return (res, num) -> {
      res.add((A)num);
    };
  }

  @Override
  public BinaryOperator<List<A>> combiner() {
    //return null;
    return (left, right) -> { left.addAll(right); return left; };
  }

  @Override
  public Function<List<A>, List<R>> finisher() {
    return i -> (List<R>) i;
  }

  @Override
  public Set<Characteristics> characteristics() {
    return Collections.emptySet();
  }

  public static void main(String[] args){
      Object fibo = Arrays.asList(1,2,3,4,5,6,7,8,9,10).stream().collect(new FiboCollector());
      System.out.println(fibo);
  }
}

